Statement |
Transaction A -- stock sale |
Transacton B -- stock purchase |
1 |
SELECT quantity_on_hand INTO qoh FROM products WHERE product_id = 123; -- now qoh = 200, say. Client checks qoh > 50 so stock is available. |
|
2 |
UPDATE products SET quantity_on_hand = quantity_on_hand + 100 WHERE product_id = 123; |
|
3 |
COMMIT; |
|
4 |
UPDATE products SET quantity_on_hand = qoh - 50; | |
5 |
COMMIT; -- now product 123 quantity_on_hand = 150, not 250 |